/*
 * 自定义校验规则
 */
// 年龄段验证
jQuery.validator.addMethod("ckages", function(value, element) {
	var min = jQuery(element).prev().val();
	var max = value;
    return min <= max;
}, "最小年龄不能大于最大年龄");

// 手机、座机验证
jQuery.validator.addMethod("istels", function(value, element) {
    var length = value.length;
    var mobile = /^1\d{10}$/;
    var telephone = /((\d{8,13})|^((\d{3,4})-(\d{7,8})|(\d{3,4})-(\d{7,8})-(\d{1,4})|(\d{7,8})-(\d{1,4}))$)/;
    return mobile.exec(value) || telephone.exec(value);
}, "请正确填写电话号码");

//座机验证
jQuery.validator.addMethod("istel", function(value, element) {
	var telephone = /((\d{8,13})|^((\d{3,4})-(\d{7,8})|(\d{3,4})-(\d{7,8})-(\d{1,4})|(\d{7,8})-(\d{1,4}))$)/;
     return telephone.exec(value);
 }, "请正确填写电话号码");
//手机验证
jQuery.validator.addMethod("ismobile", function(value, element) { 
     var mobile = /^1\d{10}$/;
     return mobile.exec(value);
 }, "请正确填写您的手机号码");
//邮编验证
 jQuery.validator.addMethod("isZipCode", function(value, element) {       
     var tel = /^[0-9]{6}$/;       
     return (tel.exec(value))?true:false;       
 }, "请正确填写您的邮编");
//邮箱地址验证
 jQuery.validator.addMethod("isEmailCode", function(value, element) {       
     var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;       
     return (email.exec(value))?true:false;       
 }, "请正确填写您的邮箱地址");
//字符验证      
 jQuery.validator.addMethod("stringCheck", function(value, element) {      
     return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);      
 }, "只能包括中文字、英文字母、数字、标点符号和下划线");  
  
 // 身份证号码验证     
 jQuery.validator.addMethod("isIdCardNo", function(value, element) {      
     return this.optional(element) || isIdCardNo(value);      
 }, "请正确输入您的身份证号码");

 /**
  * 身份证号码验证
  */ 
 function isIdCardNo(num) { 
    
  var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); 
  var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2"); 
  var varArray = new Array(); 
  var intValue; 
  var lngProduct = 0; 
  var intCheckDigit; 
  var intStrLen = num.length; 
  var idNumber = num; 
    // initialize 
      if ((intStrLen != 15) && (intStrLen != 18)) { 
          return false; 
      } 
      // check and set value 
      for(i=0;i<intStrLen;i++) { 
          varArray[i] = idNumber.charAt(i); 
          if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) { 
              return false; 
          } else if (i < 17) { 
              varArray[i] = varArray[i] * factorArr[i]; 
          }
      }
         
      if (intStrLen == 18) {
          //check date
          var date8 = idNumber.substring(6,14);
          if (isDate8(date8) == false) {
             return false;
          }
          // calculate the sum of the products 
          for(i=0;i<17;i++) {
              lngProduct = lngProduct + varArray[i];
          }
          // calculate the check digit
          intCheckDigit = parityBit[lngProduct % 11];
          // check last digit
          if (varArray[17] != intCheckDigit) {
              return false;
          }
      }
      else{   //length is 15
          //check date
          var date6 = idNumber.substring(6,12);
          if (isDate6(date6) == false) {
              return false;
          }
      }
      return true;
  }
